
#include "config.h"
#include "modules/modules.h"
#include "comm_lib.h"

int main_initialize()
{
	modules_initialize();
	return 0;
}

int main_poll()
{
	modules_poll();
	return 0;
}

int main_finalize()
{
	modules_finalize();
	return 0;
}


#ifdef SELF_TEST

#include "modules/player.h"

int main(void* argc, void** argv)
{
	comm_start_config_t config;

	//config.flags = COMM_LIB_FLAGS_SEND_ENABLE | COMM_LIB_FLAGS_RECV_ENABLE;
	config.flags = COMM_LIB_FLAGS_SEND_ENABLE;
	//config.flags = COMM_LIB_FLAGS_RECV_ENABLE;

	config.send_ip = "192.168.6.32";
	config.send_port = 10086;

	config.recv_port = 10086;
	config.pfn_comm_recv_cb = player_show_task;

	comm_start(config);

	//char test[] = "hello liweimcc \r\n";

	while(1)
	{
        main_poll();
        /*
		sleep(2);
		comm_send(0, test, sizeof(test));
		*/
	}

	main_finalize();
}

#endif

int comm_start(comm_start_config_t config)
{
	app_global.config.flags = config.flags;

	app_global.config.send_ip = inet_addr(config.send_ip);
	app_global.config.send_port = htons(config.send_port);

	app_global.config.recv_port = htons(config.recv_port);
	app_global.config.pfn_recv_cb = config.pfn_comm_recv_cb;

	return main_initialize();
}
